home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / TUTORIAL.BIN / TextField.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-01-30  |  5.8 KB  |  195 lines

  1. package symantec.itools.db.awt;
  2.  
  3. import java.awt.Event;
  4. import java.awt.TextComponent;
  5. import java.io.IOException;
  6. import symantec.itools.db.pro.ProjBinder;
  7. import symantec.itools.db.pro.ProjLink;
  8. import symantec.itools.db.pro.RelationView;
  9. import symantec.itools.db.pro.RelationViewMetaData;
  10. import symjava.sql.SQLException;
  11.  
  12. public class TextField extends java.awt.TextField implements ProjLink {
  13.    private ProjBinder m_ProjBinder;
  14.    private boolean m_DynamicUpdate = false;
  15.    private boolean m_DynamicUpdateOverride = true;
  16.    private boolean m_BinderDetermines = true;
  17.    private String m_BinderData;
  18.    private String m_ScreenData;
  19.    private int m_treatBlankAs;
  20.  
  21.    public TextField() {
  22.       this.m_BinderData = new String();
  23.       this.m_ScreenData = new String();
  24.    }
  25.  
  26.    public TextField(int cols) {
  27.       super(cols);
  28.       this.m_ScreenData = new String();
  29.       this.m_BinderData = new String();
  30.    }
  31.  
  32.    public TextField(String text) {
  33.       super(text);
  34.       this.m_ScreenData = new String();
  35.       this.m_BinderData = new String();
  36.    }
  37.  
  38.    public TextField(String text, int cols) {
  39.       super(text, cols);
  40.       this.m_ScreenData = new String();
  41.       this.m_BinderData = new String();
  42.    }
  43.  
  44.    public void init(ProjBinder binder) {
  45.       this.m_ProjBinder = binder;
  46.       this.setEditable(this.m_ProjBinder);
  47.    }
  48.  
  49.    public void setBinding(RelationView relView, String projection) {
  50.       int projectionNumber = 0;
  51.       int columnType = 0;
  52.  
  53.       try {
  54.          RelationViewMetaData rvmd = relView.getMetaData();
  55.          projectionNumber = relView.findProjByName(projection);
  56.          columnType = rvmd.getColumnType(projectionNumber);
  57.          if (columnType == 91 || columnType == 92 || columnType == 93) {
  58.             this.m_DynamicUpdateOverride = false;
  59.          }
  60.  
  61.          relView.bindProj(projectionNumber, this);
  62.       } catch (SQLException Ex) {
  63.          this.raiseException("SQLException from setBinding: " + ((Throwable)Ex).getMessage());
  64.       }
  65.    }
  66.  
  67.    public void setDynamicUpdate(boolean update) {
  68.       this.m_DynamicUpdate = update;
  69.    }
  70.  
  71.    public void setTreatBlankAs(String blank) {
  72.       if ((new String(blank)).toUpperCase().equals("DEFAULT")) {
  73.          this.m_treatBlankAs = 0;
  74.       } else if ((new String(blank)).toUpperCase().equals("NULL")) {
  75.          this.m_treatBlankAs = 1;
  76.       } else {
  77.          if ((new String(blank)).toUpperCase().equals("EMPTY")) {
  78.             this.m_treatBlankAs = 2;
  79.          }
  80.  
  81.       }
  82.    }
  83.  
  84.    public void notifyDataChange(ProjBinder binder) {
  85.       if (binder != null) {
  86.          this.m_ProjBinder = binder;
  87.  
  88.          try {
  89.             if (binder.getRelationView().getCurrentRecordState() != 105) {
  90.                if (binder.isReadable() && !binder.isNull()) {
  91.                   this.m_BinderData = binder.getStringValue();
  92.                } else {
  93.                   this.m_BinderData = "";
  94.                }
  95.             } else {
  96.                this.m_BinderData = "";
  97.             }
  98.          } catch (SQLException Ex) {
  99.             this.raiseException("SQLException from TextField.notifyDataChange.getString: " + ((Throwable)Ex).getMessage());
  100.          } catch (IOException Ex) {
  101.             this.raiseException("IOException from TextField.notifyDataChange.getString: " + ((Throwable)Ex).getMessage());
  102.          }
  103.  
  104.          if (this.m_BinderData == null) {
  105.             this.m_BinderData = new String();
  106.          }
  107.  
  108.          this.m_ScreenData = ((TextComponent)this).getText();
  109.          if (!this.m_BinderData.equals(this.m_ScreenData)) {
  110.             this.m_ScreenData = this.m_BinderData;
  111.             ((TextComponent)this).setText(this.m_ScreenData);
  112.          }
  113.  
  114.          if (this.m_BinderDetermines) {
  115.             this.setEditable(this.m_ProjBinder);
  116.          }
  117.  
  118.       }
  119.    }
  120.  
  121.    public boolean lostFocus(Event evt, Object what) {
  122.       try {
  123.          this.notifySetData(this.m_ProjBinder);
  124.       } catch (SQLException Ex) {
  125.          this.raiseException("SQLException from TextField.notifySetData: " + ((Throwable)Ex).getMessage());
  126.       }
  127.  
  128.       return super.lostFocus(evt, what);
  129.    }
  130.  
  131.    boolean notifyInputChanged(String input) {
  132.       if (!this.m_ScreenData.equals(input)) {
  133.          this.m_ScreenData = input;
  134.       }
  135.  
  136.       if (!this.m_BinderData.equals(this.m_ScreenData)) {
  137.          this.m_BinderData = this.m_ScreenData;
  138.  
  139.          try {
  140.             this.m_ProjBinder.setValueFromString(this.m_ScreenData, 0, this.m_treatBlankAs);
  141.          } catch (SQLException Ex) {
  142.             this.raiseException("SQLException from TextField.notifyInputChange: " + ((Throwable)Ex).getMessage());
  143.             return false;
  144.          } catch (IOException Ex) {
  145.             this.raiseException("IOException from TextField.notifyInputChange: " + ((Throwable)Ex).getMessage());
  146.             return false;
  147.          }
  148.       }
  149.  
  150.       return true;
  151.    }
  152.  
  153.    public boolean notifySetData(ProjBinder binder) throws SQLException {
  154.       return this.notifyInputChanged(((TextComponent)this).getText());
  155.    }
  156.  
  157.    public boolean handleEvent(Event evt) {
  158.       if (this.m_DynamicUpdate && this.m_DynamicUpdateOverride) {
  159.          try {
  160.             this.notifySetData(this.m_ProjBinder);
  161.          } catch (SQLException Ex) {
  162.             this.raiseException("SQLException from TextField.notifySetData: " + ((Throwable)Ex).getMessage());
  163.          }
  164.       }
  165.  
  166.       return super.handleEvent(evt);
  167.    }
  168.  
  169.    void setEditable(ProjBinder binder) {
  170.       boolean isWritable = false;
  171.  
  172.       try {
  173.          if (binder != null) {
  174.             RelationView rv = binder.getRelationView();
  175.             if (rv != null && rv.getCurrentRecordState() != 105) {
  176.                isWritable = binder.isWritable();
  177.             }
  178.          }
  179.       } catch (SQLException Ex) {
  180.          this.raiseException("SQLException from setEditable: " + ((Throwable)Ex).getMessage());
  181.       }
  182.  
  183.       super.setEditable(isWritable);
  184.    }
  185.  
  186.    public void setEditable(boolean value) {
  187.       this.m_BinderDetermines = value;
  188.       super.setEditable(value);
  189.    }
  190.  
  191.    void raiseException(String text) {
  192.       System.out.println(text);
  193.    }
  194. }
  195.